import 'package:fluro/fluro.dart';
import 'package:flutter/material.dart';
import 'package:riverpod_t/page/car/router/car_router.dart';
import 'package:riverpod_t/page/home/router/home_router.dart';

class NovelRoutes {
  static final List<ModuleRouter> _listRouter = [];
  static final FluroRouter _fluroRouter = FluroRouter();

  static FluroRouter get fluroRouter => _fluroRouter;

  static void initRoutes() {
    _fluroRouter.notFoundHandler =
        Handler(handlerFunc: (BuildContext? context, Map<String, List<String>> params) {
      return Container(
        color: Colors.transparent,
        child: const Text('页面找不到了~'),
      );
    });

    _listRouter.clear();
    _listRouter.addAll([
      HomeNavigator.getRouter(),
      CarNavigator.getRouter(),
    ]);

    void initRouter(ModuleRouter router) {
      router.init(_fluroRouter);
    }

    _listRouter.forEach(initRouter);
  }
}

abstract class ModuleRouter {
  void init(FluroRouter router);
}
